<?php
/*
 * Admin Base Controller
 *
 * */

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;

class BaseController extends Controller
{
    //

    /*
     * form validator
     * */
    public function formValidator($input, $rules, $messages)
    {
        return Validator::make($input, $rules, $messages);
    }

    /*
     *  make tourist table num
     * */
    public function getTableNum($phone)
    {
        return '_' .fmod($phone,100);
    }

    /*
     * tourist search
     * */
    public function regexSearch($str = '', $type = '')
    {
        $matches = [];
        if (!$type) {
            preg_match_all('/[a-z]+[0-9]+/', $str, $matches);
        } else {
            if ($type == 'word') {
                preg_match_all('/[a-z]+/', $str, $matches);
            }
            if ($type == 'number') {
                preg_match_all('/[0-9]+/', $str, $matches);
            }
        }
        return $matches[0];
    }


    /*
     * return api msg
     * */
    public function apiMessage($success = false, $msg = '', $data = [])
    {
        $arr = [];
        if ($success) {
            $arr = [
                'success' => $success,
                'msg' => $msg,
                'data' => $data
            ];
        } else {
            $arr = [
                'success' => $success,
                'msg' => $msg
            ];
        }
        return $arr;
    }
}
